package com.allen.app.zdemo.domain;

import lombok.Getter;

/**
 * Description: 延时队列配置
 *
 * @author Limiaojun
 * @date 2019/12/28 17:21
 **/
public enum DelayExchange {
    TEST_MQ_DLX("xxx-server.test-mq-delay-exchange", new DelayQueues[]{DelayQueues.TEST_MQ_DLX_QUEUE}),
    TEST_MQ_PLUGS_DLX("xxx-server.test-mq-plugs-delay-exchange", new DelayQueues[]{DelayQueues.TEST_MQ_PLUGS_DLX_QUEUE},true);

    @Getter
    String exchangeName;
    @Getter
    DelayQueues[] queues;
    //新延迟队列直接信道流转到队列,不需要延迟队列中转。数据需要自己记录到数据库,控制台看不到数据。只能看到数字
    @Getter
    boolean isPlugsDelay = false;

    //该延迟队列会存在时间不一致堵塞问题
    DelayExchange(String exchangeName, DelayQueues[] queues) {
        this.exchangeName = exchangeName;
        this.queues = queues;
    }

    //支持延时时间不一致问题,需要安装插件 x-delayed-message,注意对应版本
    DelayExchange(String exchangeName, DelayQueues[] queues, boolean isPlugsDelay) {
        this.exchangeName = exchangeName;
        this.queues = queues;
        this.isPlugsDelay = isPlugsDelay;
    }

    public enum DelayQueues {
        TEST_MQ_DLX_QUEUE("xxx-server.test-mq-delay-exchange.test-mq.dlx", "xxx-server.test-mq-delay-exchange.test-mq.receive",5000L),
        TEST_MQ_PLUGS_DLX_QUEUE("", "xxx-server.test-mq-plugs-delay-exchange.test-mq.receive",5000L);


        @Getter
        String delayName;
        @Getter
        String forwardName;
        @Getter
        Long timeout;

        DelayQueues(String delayName, String forwardName, Long timeout) {
            this.delayName = delayName;
            this.forwardName = forwardName;
            this.timeout = timeout;
        }
    }
}
